import Mock from 'mockjs'

let List = []
const count = 1000
let typelist = ['联通', '移动', '电信', '铁通']

for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    id: Mock.Random.guid(),
    sortnum: i + 1,
    username: Mock.Random.cname(),
    address: Mock.mock('@county(true)'),
    createTime: Mock.Random.datetime(),
    updateTime: Mock.Random.now(),
    ip: Mock.mock('@ip'),
    region: Mock.mock('@region'),
    areaId: /\d{7}/,
    email: Mock.Random.email(),
    'isp|1': typelist
  }))
}
export default {
  // 用户登录
  login: config => {
    let data = config.body.split("&");
    let obj = {};
    data.map(item => {
      let arr = [];
      arr = item.split("=");
      obj[arr[0]] = arr[1]
    });
    let userList = {};
    if (obj.username === 'admin') {
      userList = {
        token: 'admin',
        name: '超级管理员',
      }
    } else if (obj.username === 'editor') {
      userList = {
        token: 'editor',
        name: '赵晓编',
      }
    } else {
      return {
        code: -1,
        data: {
          msg: "用户名错误",
          status: 'fail'
        }
      }
    }
    return {
      code: 200,
      data: userList
    }
  },
  // 用户登出
  logOut: config => {
    return {
      code: 200,
      data: {
        userList: ""
      }
    }
  },
  // 获取登录用户信息
  getUserInfo: config => {
    let data = config.body.split("=");
    let obj = {};
    obj[data[0]] = data[1]
    let userList = {};
    if (obj.token === 'admin') {
      userList = {
        roles: ['admin'],
        name: '超级管理员',
      }
    } else if (obj.token === 'editor') {
      userList = {
        roles: ['editor'],
        name: '赵晓编',
      }
    } else {
      userList = {}
    }
    return {
      code: 200,
      data: userList
    }
  },

}
